package com.zeyi.web.utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import com.zeyi.common.utils.SecurityUtils;
import com.zeyi.storage.cloud.OssStorageFactory;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

public class UploadUtils {
    public static String upload(MultipartFile file) throws IOException {
        String path = new StringBuffer(SecureUtil.md5(String.valueOf(SecurityUtils.getUserId())))
                .append(CharUtil.SLASH)
                .append(IdUtil.simpleUUID())
                .append(CharUtil.DOT)
                .append(FileUtil.extName(file.getOriginalFilename())).toString();
        return OssStorageFactory.build().upload(file.getInputStream(), path);
    }
}
